<template>
  <div></div>
</template>

<script>
//Honinbo的菜单
import Bus from "emitvue";
let remote = require("electron").remote;
let Menu = remote.Menu;
export default {
  data() {
    return {
      whiteLocked: false,
      blackLocked: false,
      switchLocked: true,
      lockStatus :0, //0交替  1下黑子 2 下白子
    };
  },
  methods: {
      //切换按钮选择状态
      switchLock(type) {
          console.log('type,this.lockStatus :>> ', type,this.lockStatus);
          switch (type) {
              case null:
                  if(this.lockStatus === 0 ) {
                      return;
                  } else {
                      this.lockStatus = 0;
                      this.switchLocked = true;
                      this.whiteLocked = false;
                      this.blackLocked = false;
                      Bus.$emit('switchLock',null);
                      this.$Message.info("切换为交替落子")
                  }
                  break;
              case true:
                  if(this.lockStatus === 1 ) {
                      return;
                  } else {
                      this.lockStatus = 1;
                      this.switchLocked = false;
                      this.whiteLocked = false;
                      this.blackLocked = true;
                      this.$Message.info("切换为落黑子")
                      Bus.$emit('switchLock',true);

                  }
                  break;
               case false:
                   if(this.lockStatus === -1 ) {
                      return;
                  } else {
                      this.lockStatus = -1;
                      this.switchLocked = false;
                      this.whiteLocked = true;
                      this.blackLocked = false;
                      this.$Message.info("切换为落白子")
                      Bus.$emit('switchLock',false);
                  }
                  break;
              default:
                  break;
          }
          if((this.switchLocked === false) && (this.blackLocked === false) && (this.whiteLocked === false)) {
              this.switchLocked = true;
          }
          this.createMenu();
      },
      
    createMenu() {
      let template = [
        {
          label: "菜单",
          submenu: [
            {
              label: "新的一局",
              accelerator:'shift+N',
              click: () => {
                Bus.$emit("newGame");
              },
            },
          ],
        },
        {
          label: "工具",
          submenu: [
            {
              label: "落子控制",
              submenu: [
                {
                  label: "交替落子",
                  type: "checkbox",
                  click: () => {
                    this.switchLock(null);
                  },
                  checked: this.switchLocked,
                  accelerator:'shift+1',
                },
                {
                  label: "落黑子",
                  type: "checkbox",
                  checked: this.blackLocked,
                  accelerator:'shift+2',
                  click: () => {
                    this.switchLock(true);
                  },
                },
                {
                  label: "落白子",
                  type: "checkbox",
                  checked: this.whiteLocked,
                  accelerator:'shift+3',
                  click: () => {
                    this.switchLock(false);
                  },
                },
                
              ],
            },
            {
                label:"形式判断",
                accelerator:'alt+shift+3',
                  click: () => {
                    this.checkInfluence();
                  },
            }
          ],
        },
      ];
      var menu = Menu.buildFromTemplate(template);
      Menu.setApplicationMenu(menu);
    },
    checkInfluence() {
        console.log('11 :>> ', 11);
    },
  },
  mounted() {
    this.createMenu();
  },
};
</script>

<style>
</style>